package com.song.JavaThread_ch3_2;

import java.util.concurrent.Semaphore;

public class PrintQueue {
	
	private final Semaphore semaphore;

	public PrintQueue() {
		super();
		
		semaphore = new Semaphore(1);
	}
	
	public void printJob(Object document)
	{
		
		try {
			semaphore.acquire();
			long duration = (long)(Math.random()*10);
			System.out.printf("%s : print a job duration %d  \n" ,Thread.currentThread().getName(),duration);
			Thread.sleep(duration);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			semaphore.release();
		}
		
	}
	
	
	
}
